import 'package:flutter/material.dart';
import 'package:kk/pages/home_page.dart';
import 'package:kk/pages/my_page.dart';
import 'package:kk/pages/search_page.dart';
import 'package:kk/pages/travel_page.dart';

class NavigatorPage extends StatefulWidget {
  const NavigatorPage();

  @override
  State<NavigatorPage> createState() => _NavigatorPageState();
}

class _NavigatorPageState extends State<NavigatorPage> {
  final PageController _controller = PageController(initialPage: 0);
  final _defaultColor = Colors.grey;
  final _activeColor = Colors.blue;
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: [
          HomePage(),
          SearchPage(
            hideLeft: true,
          ),
          TravelPage(),
          MyPage()
        ],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index) {
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          selectedItemColor: _activeColor,
          selectedFontSize: 14.0,
          type: BottomNavigationBarType.fixed,
          items: [
            _genBottomNavgatorItem("首页", Icons.home),
            _genBottomNavgatorItem("搜索", Icons.search),
            _genBottomNavgatorItem("旅游", Icons.camera_alt),
            _genBottomNavgatorItem("我的", Icons.account_circle),
          ]),
    );
  }

  _genBottomNavgatorItem(
    String text,
    IconData icon,
  ) {
    return BottomNavigationBarItem(
        label: text,
        icon: Icon(
          icon,
          color: _defaultColor,
        ),
        activeIcon: Icon(
          icon,
          color: _activeColor,
        ));
  }
}
